import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';

import { DICT_TYPE } from '@vben/constants';
import { getDictOptions } from '@vben/hooks';

import { $t } from '#/locales';

/** 列表的搜索表单 */
export function useGridFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'name',
      label: $t('views.crm.customer.name'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.crm.customer.namePlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'mobile',
      label: $t('views.crm.common.mobile'),
      component: 'Input',
      componentProps: {
        placeholder: $t('views.crm.common.mobilePlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'industryId',
      label: $t('views.crm.common.industryId'),
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CRM_CUSTOMER_INDUSTRY, 'number'),
        placeholder: $t('views.crm.common.industryIdPlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'level',
      label: $t('views.crm.common.level'),
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CRM_CUSTOMER_LEVEL, 'number'),
        placeholder: $t('views.crm.common.levelPlaceholder'),
        allowClear: true,
      },
    },
    {
      fieldName: 'source',
      label: $t('views.crm.common.source'),
      component: 'Select',
      componentProps: {
        options: getDictOptions(DICT_TYPE.CRM_CUSTOMER_SOURCE, 'number'),
        placeholder: $t('views.crm.common.sourcePlaceholder'),
        allowClear: true,
      },
    },
  ];
}

export function useGridColumns(): VxeTableGridOptions['columns'] {
  return [
    {
      title: $t('views.crm.customer.name'),
      field: 'name',
      minWidth: 160,
      fixed: 'left',
      slots: { default: 'name' },
    },
    {
      title: $t('views.crm.common.source'),
      field: 'source',
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CRM_CUSTOMER_SOURCE },
      },
    },
    {
      title: $t('views.crm.common.mobile'),
      field: 'mobile',
      minWidth: 120,
    },
    {
      title: $t('views.crm.common.telephone'),
      field: 'telephone',
      minWidth: 120,
    },
    {
      title: $t('views.crm.common.email'),
      field: 'email',
      minWidth: 140,
    },
    {
      title: $t('views.crm.common.level'),
      field: 'level',
      minWidth: 135,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CRM_CUSTOMER_LEVEL },
      },
    },
    {
      title: $t('views.crm.common.industryId'),
      field: 'industryId',
      minWidth: 100,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.CRM_CUSTOMER_INDUSTRY },
      },
    },
    {
      title: $t('views.crm.followUp.contactNextTime'),
      field: 'contactNextTime',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.remark'),
      field: 'remark',
      minWidth: 200,
    },
    {
      title: $t('views.crm.customer.detail.dealStatus'),
      field: 'dealStatus',
      minWidth: 90,
      cellRender: {
        name: 'CellDict',
        props: { type: DICT_TYPE.INFRA_BOOLEAN_STRING },
      },
    },
    {
      title: $t('views.crm.followUp.contactLastTime'),
      field: 'contactLastTime',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('views.crm.followUp.contactLastContent'),
      field: 'contactLastContent',
      minWidth: 200,
    },
    {
      title: $t('common.updateTime'),
      field: 'updateTime',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('common.createTime'),
      field: 'createTime',
      minWidth: 180,
      formatter: 'formatDateTime',
    },
    {
      title: $t('views.common.creatorName'),
      field: 'creatorName',
      minWidth: 100,
    },
  ];
}
